package com.qf.ssm.result;

import lombok.Data;

/**
 * 状态的跟信息
 *
 * @param <T>
 */
@Data
public class ResponseResult<T> {
    private int code;
    private String msg;
    private T data;

    public static <T> ResponseResult<T> success(T data) {
        return success(ResultStatus.SUCCESS, data);
    }

    public static <T> ResponseResult<T> success(ResultStatus resultStatus, T data) {
        return common(resultStatus, data);
    }

    public static <T> ResponseResult<T> error(ResultStatus resultStatus) {
        return common(resultStatus, null);
    }

    public static <T> ResponseResult<T> error() {
        return error(ResultStatus.SYS_ERROR);
    }

    private static <T> ResponseResult<T> common(ResultStatus resultStatus, T data) {
        ResponseResult<T> result = new ResponseResult<>();
        result.setCode(resultStatus.getCode());
        result.setMsg(resultStatus.getMsg());
        result.setData(data);
        return result;
    }

}
